/** @file    FormPopup.cpp
 *  @author  Alessandro Polo
 *  @version $Id: FormPopup.cpp 1708 2010-01-26 22:28:01Z alex $
 *  @brief
 * File containing methods for the wosh::FormPopup class.
 * The header for this class can be found in FormPopup.h, check that file
 * for class description.
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

 #include "FormPopup.h"

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////// CONSTRUCTORS

FormPopup::FormPopup() : QFrame()
 {
	this->frmTxtEditor = NULL;
	this->timer = NULL;

	this->setAttribute(Qt::WA_DeleteOnClose, false);
	this->setAttribute(Qt::WA_QuitOnClose, false);
	this->setWindowFlags( Qt::Popup | Qt::Window );

	QVBoxLayout * verticalLayout = new QVBoxLayout(this);
	verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));

	this->frmTxtEditor = new QTextBrowser( this );
	verticalLayout->addWidget(this->frmTxtEditor);
	//this->frmTxtEditor->setGeometry(10,10, width, height);
	this->frmTxtEditor->setFrameShape( QFrame::NoFrame );
	this->frmTxtEditor->setFocus();

	connect(this, SIGNAL(clicked()), this, SLOT(clicked_me()));
	connect(this->frmTxtEditor, SIGNAL(clicked()), this, SLOT(clicked_te()));

	this->timer = new QTimer(this);
	this->timer->setSingleShot(false);
	this->timer->setInterval(100);
	connect(this->timer, SIGNAL(timeout()), this, SLOT(timer_timeout()));

	connect(this, SIGNAL(display_s()), this, SLOT(display()));

 }


FormPopup::~FormPopup()
 {

	this->close();

 }

//////////////////////////////////////////////////////////////////////////////////////////////// CONSTRUCTORS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////// BUNDLE CONTROL


//////////////////////////////////////////////////////////////////////////////////////// PROCESS BUS MESSAGES
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////// PROPERTY EVENT


//////////////////////////////////////////////////////////////////////////////////////////////////////////////

void FormPopup::showMessage( const string& message )
 {

	QString msg = QString::fromLatin1(message.c_str());

	this->frmTxtEditor->setText( msg );

	emit display_s();

 }

void FormPopup::display()
 {
 	int width = 250;
	int height = 150;
	QRect screen = QApplication::desktop()->screenGeometry();

	this->setGeometry( screen.adjusted( screen.right()-width,screen.bottom()-height , 0,0 ) );

	this->show();

 }

void FormPopup::timer_timeout()
 {


 }
 
void FormPopup::clicked_te()
 {
	this->hide();
 }
void FormPopup::clicked_me()
 {
	this->hide();
 }

 